package com.crcchem.practice.demos.web.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @projectName: code-training
 * @package: com.crcchem.practice.demos.web.config
 * @className: CorsConfig
 * @author: 李富强
 * @description: TODO
 * @date: 2025/8/21 15:05
 * @version: 1.0
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*") // 允许所有前端地址
                .allowedMethods("GET", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*") // 允许所有头部，包括 Authorization
                .allowCredentials(false)
                .maxAge(3600);
    }
}
